# -*- coding: utf-8 -*-
# @Time : 2021/9/4 9:03
# @Author : 唐宁
# @Site : 
# @File : OrderService.py
# @Software: PyCharm
from core.order.dao.OrderDao import OrderDao
from exception.ErrorCodeEnum import ErrorCodeEnum
from exception.ErrorCodeException import ErrorCodeException


class OrderService:

    @classmethod
    def getOrderList(cls, dto):
        """
        查询订单列表
        :param dto:  查询参数
        :return:  list
        """
        return OrderDao.getOrderList(dto)

    @classmethod
    def getOrderListPage(cls, dto):
        """
        查询订单列表
        :param dto:  查询参数
        :return: page_info
        """
        # 获取page信息
        page_info = OrderDao.getOrderListPage(dto)
        # 处理分页查询的数据信息（仅举例说明取值）
        for order_info in page_info.rows:
            print("示例:order_id ==> ", order_info.id)
        return page_info

    @classmethod
    def getOrderInfo(cls, orderId, productName):
        """
        获取单个订单信息
        :param orderId: 订单ID
        :param productName: 商品名称
        :return: 订单信息
        """
        return OrderDao.getOrderInfo(orderId)

    @classmethod
    def updateOrderNo(cls, orderId, orderNo):
        """
        更新订单编号
        :param orderId: 订单ID
        :param orderNo:  订单编号
        :return:  str
        """
        # 订单校验
        if OrderDao.getOrderInfo(orderId) is None:
            raise ErrorCodeException(ErrorCodeEnum.NO, "查询不到该订单")
        # 更新订单
        OrderDao.updateOrderNo(orderId, orderNo)
        return "更新成功"
